import { defineStore } from "pinia"
import { onMounted, ref } from "vue"
import { get, post } from "@/utils/api"
import { MessagePlugin } from "tdesign-vue-next"

export const useAdminCopyrightStore = defineStore("adminCopyright", () => {
  const showType = ref("1")
  const common = {
    saveConfig: async () => {
      try {
        const response = await post("/api/copyright/saveConfig", copyright.formData.value)
        MessagePlugin(response.status, response.message)
        await copyright.getConfig()
      } catch (err) {
        console.log(err)
      }
    }
  }
  const copyright = {
    formData: ref({
      id: 1,
      copyright: "",
      icp: "",
    }),
    getConfig: async () => {
      try {
        const config = await get("/api/copyright/getConfig")
        console.log(config)
        if(config !== null){
          copyright.formData.value = config
        }
      } catch (err) {
        console.log(err)
      }
    },
  }
  onMounted(async () => {
    await copyright.getConfig()
  })

  return {
    common,
    showType,
    copyright
  }
})
